package com.example.trabalho;




import java.util.ArrayList;

import android.R.anim;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends Activity {

	Spinner spi;
	Button bt1,bt2,bt3;
	ListView listaCombo;
	String pedidoSelecionado="";
	int pedidoExcluir;
	String[] lista = new String[]{
		"CERVEJA R$ 5,00","REFRIGERANTE R$ 3,00","ESPETINHO R$ 2,00", "VODKA R$ 5,00","Whisky R$ 10,00"	
			
	};
	ArrayList<String> listaAdd = new ArrayList<String>();
	
	Bundle parametros = new Bundle();
	
	ArrayAdapter adaptador;
	
	ArrayAdapter adaptadorLista;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		spi = (Spinner) findViewById(R.id.combo);
		listaCombo = (ListView) findViewById(R.id.lista);
		
		
		bt1= (Button) findViewById(R.id.btadd);
		bt2 = (Button) findViewById(R.id.btPedido);
		bt3 = (Button) findViewById(R.id.btexcluir);
		
		adaptador =new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,lista);
		adaptador.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spi.setAdapter(adaptador);
		
		
		adaptadorLista =new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,listaAdd);
		adaptadorLista.setDropDownViewResource(android.R.layout.simple_list_item_checked);
		listaCombo.setAdapter(adaptadorLista);

		spi.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1, int posicao, long arg3) {
				
				pedidoSelecionado = lista[posicao];
					
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub
				
			}
			
			
		});
		
		listaCombo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			
			
	
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					
		
					int posicaoo, long arg3) {
				pedidoExcluir = posicaoo;
				
			}

		});
		
		
		bt1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				
			listaAdd.add(pedidoSelecionado);	
			adaptadorLista.notifyDataSetChanged();	
			
			Toast.makeText( MainActivity.this, " "+pedidoSelecionado, Toast.LENGTH_LONG).show();
			}
		});
		
		
		bt2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				Intent itTelaPrincipal = new Intent(MainActivity.this, Tela2.class);
				 
				
				itTelaPrincipal.putStringArrayListExtra("lista", listaAdd);
				
				
				startActivity(itTelaPrincipal);
				
				MainActivity.this.finish();

				
			}
		});
		
	bt3.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				
			listaAdd.remove(pedidoExcluir);	
			adaptadorLista.notifyDataSetChanged();	
			
			
			}
		});
		
		
		
	}

}
	
	
	
	
	

